home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / manchest.lha / MANCHESTER / manchester / 4.1 / SUNFunKey.st < prev    next >
Text File  |  1993-07-24  |  8KB  |  276 lines

  1. "    NAME        SUNFunKey
  2.     AUTHOR        Mario Wolczko <mario@cs.man.ac.uk>
  3.     FUNCTION    Binds functions to keys on the SUN type-4 keyboard
  4.     ST-VERSION    4.1
  5.     PREREQUISITES    
  6.     CONFLICTS
  7.     DISTRIBUTION     world
  8.     VERSION        1
  9.     DATE    27 March 1993
  10. SUMMARY
  11. This goodie binds the usual Again,Undo,Copy,Paste and Cut functions to the keys
  12. with those keysyms on the SUN Type 4 keyboard.  (You may need to use xmodmap
  13. to set up the appropriate mappings; a fragment of a suitable file is included below.)
  14. On the numeric pad, Enter is bound to Accept, Home moves to the
  15. beginning of the line, End moves to the end of line, R1, R2 and R3 do
  16. it, print it, and inspect it.
  17. It also binds the LineFeed key to a function that inserts a newline, and copies
  18. indentation from the previous line (this was adapted from a ParcPlace VI2.5
  19. goodie, FunctKey.st).
  20. It should be obvious how to bind other keys following this scheme.
  21. In general:
  22. 1. Ensure that your window system is mapping the key to an appropriate key symbol.
  23.    If not, use xmodmap to achieve the mapping.  xev is a useful program for
  24.    finding which keycode is generated by a key. 
  25.    Names of X11 keysyms can usually be found in /usr/include/X11/keysymdef.h
  26.    and InputState class>initKeys.
  27. 2. Add a suitable line to ParagraphEditor>initializeSUNkeys to associate the keysym
  28.    with a method.  Write the method if necessary.
  29. 3. Reinitialize ParagraphEditor.  New windows will use the new mapping.
  30.  
  31. Here is a chunk of input for xmodmap:
  32. !! map for SUN Type 4 keyboards (PC like)
  33. !! each code has 2 syms: normal and shifted
  34. !!
  35. !! keys at left of keyboard
  36. !!
  37. !! Stop
  38. keycode 8=L1
  39. !! Again
  40. keycode 10=L2
  41. !! Props
  42. keycode 32=L3
  43. keycode 33=L4
  44. !! Front
  45. keycode 56=L5
  46. !! Copy
  47. keycode 58=L6
  48. !! Open
  49. keycode 79=L7
  50. !! Paste
  51. keycode 80=L8
  52. keycode 102=L9
  53. !! Cut
  54. keycode 104=L10
  55. !!
  56. !! keys at top
  57. keycode 12=F1
  58. keycode 13=F2
  59. keycode 15=F3
  60. keycode 17=F4
  61. keycode 19=F5
  62. keycode 21=F6
  63. keycode 23=F7
  64. keycode 24=F8
  65. keycode 25=F9
  66. keycode 14=F10
  67. !! keysyms F11 and F12 are the same as L1 and L2 in keysymdef.h
  68. !!
  69. !! keys at right
  70. !! Pause R1
  71. keycode 28=R1
  72. !! PrSc R2
  73. keycode 29=R2
  74. !! Scroll Lock Break R3
  75. keycode 30=R3
  76. !! Num Lock
  77. keycode 105=Num_Lock
  78. !! = R4
  79. keycode 52=R4
  80. !! / R5
  81. keycode 53=R5
  82. !! * R6
  83. keycode 54=R6
  84. !! -
  85. !!keycode 78=
  86. !! 7 Home R7
  87. keycode 75=Home
  88. !! 8 Up R8
  89. keycode 76=Up
  90. !! 9 PgUp R9
  91. keycode 77=R9
  92. !! +
  93. !! keycode 132=plus KP_Add
  94. !! 4 Left R10
  95. keycode 98=Left
  96. !! 5 R11
  97. keycode 99=R11 
  98. !! 6 Right R12
  99. keycode 100=Right
  100. !! 1 End R13
  101. keycode 119=End
  102. !! 2 Down R14
  103. keycode 120=Down
  104. !! 3 PgDn R15
  105. keycode 121=R15
  106. !! Enter
  107. keycode 97=KP_Enter
  108. !! 0 Ins
  109. keycode 101=Insert
  110. !! . Del
  111. keycode 57=Delete
  112.  
  113. "
  114. 'From Objectworks(r)\Smalltalk, Release 4 of 25 October 1990 on 2 March 1991 at 3:48:42 pm'!
  115.  
  116. !ParagraphEditor methodsFor: 'editing'!
  117.  
  118. againKey: aChar
  119.     "Repeat the last edit"
  120.  
  121.     self again!
  122.  
  123. copySelectionKey: aChar
  124.     "Copy the current text selection."
  125.  
  126.     self copySelection!
  127.  
  128. echoInputKey: aCharEvent
  129.     "A bizarre character has been received: echo its value to the Transcript, but ignore it otherwise."
  130.  
  131.     Transcript show: 'Unknown key: ',aCharEvent keyValue printString; cr.
  132.     self ignoreInputKey: aCharEvent!
  133.  
  134. indentedCRKey: aChar
  135.     "Replace the current text selection with a CR plus 
  136.     the number of tabs and spaces found at the beginning of 
  137.     the current line."
  138.     "Based on a (rather inefficient) version from ParcPlace."
  139.  
  140.     | text index character characterStream ssi |
  141.  
  142.     "Sniff backwards along text string till CR or beginning of string."
  143.     text := self paragraph text.
  144.     index := ssi := self selectionStartIndex.
  145.     "test for empty text"
  146.     index = 1 ifTrue: [self appendToSelection: (String with: CR).  ^self].
  147.     character := nil.
  148.     [index := index - 1.
  149.     character := text at: index.
  150.     character = CR or: [index = 1]]
  151.         whileFalse.
  152.  
  153.     "Special exit for immediate encounter of CR."
  154.     (ssi - 1 = index)
  155.         ifTrue: [self appendToSelection: (String with: CR).  ^self].
  156.  
  157.     "Now accumulate whitespace into characterStream till first non-white  
  158.     character, or end of string."
  159.     characterStream := (String new: 8) writeStream.
  160.     characterStream nextPut: CR.
  161.     character == CR ifTrue: [index := index + 1].
  162.     character := text at: index.
  163.     [character = Tab | (character = Space) & (index < ssi)]
  164.         whileTrue: 
  165.             [characterStream nextPut: character.
  166.             index := index + 1.
  167.             index < ssi ifTrue: [character := text at: index]].
  168.     self appendToSelection: characterStream contents!
  169.  
  170. doItKey: aChar
  171.     self doIt!
  172.  
  173. inspectItKey: aChar
  174.     self inspectIt!
  175.  
  176. printItKey: aChar
  177.     self printIt! !
  178.  
  179. !ParagraphEditor class methodsFor: 'class initialization'!
  180.  
  181. initialize
  182.     "Initialize the yellow button menu information, the keyboard map for special
  183.     control characters, and the shared buffers for copying text across views and
  184.     managing undo."
  185.  
  186.     "ParagraphEditor initialize."
  187.     PreviousSelections := OrderedCollection with: ' ' asText.
  188.     self currentSelection: (self undoSelection: Text new).
  189.     TextEditorYellowButtonMenu := 
  190.         PopUpMenu labels: 'again\undo\copy\cut\paste\accept\cancel' withCRs
  191.                     lines: #(2 5 )
  192.                     values: #(again undo copySelection cut paste accept cancel).
  193.     CodeYellowButtonMenu := 
  194.         PopUpMenu 
  195.             labelList: #((again undo) (copy cut paste) ('do it' 'print it' 'inspect') (accept cancel) (hardcopy))
  196.             values: #(again undo copySelection cut paste doIt printIt inspectIt accept cancel hardcopy).
  197.     self initializeDispatchTable.
  198.     self initializeSUNKeys.
  199.     CompilationErrorSignal := (self errorSignal newSignalMayProceed: true)
  200.         notifierString: 'Compilation failed';
  201.         nameClass: self message: #compilationErrorSignal.!
  202.  
  203. initializeDispatchTable
  204.     "Initialize the keyboard dispatch table."
  205.     "ParagraphEditor initializeDispatchTable."
  206.  
  207.     Keyboard := DispatchTable new. 
  208.  
  209.     Keyboard defaultForCharacters: #normalCharacterKey:.
  210.     Keyboard defaultForNonCharacters: #echoInputKey:.
  211.  
  212.     Keyboard bindValue: #backspaceKey: to: Cut.
  213.     Keyboard bindValue: #pasteKey: to: Paste.
  214.     Keyboard bindValue: #backspaceKey: to: BS.
  215.     Keyboard bindValue: #backWordKey: to: Ctrlw.
  216.  
  217.     Keyboard bindValue: #displayIfTrueKey: to: Ctrlt.
  218.     Keyboard bindValue: #displayIfFalseKey: to: Ctrlf.
  219.     Keyboard bindValue: #displayDateKey: to: Ctrld.
  220.     Keyboard bindValue: #displayColonEqualKey: to: Ctrlg.
  221.  
  222.     "Keyboard bindValue: #displayCRKey: to: #Enter."
  223.  
  224.     Keyboard bindValue: #cursorUpKey: to: #Up.
  225.     Keyboard bindValue: #cursorDownKey: to: #Down.
  226.     Keyboard bindValue: #cursorLeftKey: to: #Left.
  227.     Keyboard bindValue: #cursorRightKey: to: #Right.
  228.  
  229.     Keyboard bindValue: #homeKey: to: #Home.
  230.     Keyboard bindValue: #endKey: to: #End.
  231.     Keyboard bindValue: #pageUpKey: to: #PageUp.
  232.     Keyboard bindValue: #pageDownKey: to: #PageDown.
  233.  
  234.     '<''"[{(' do:
  235.         [:char |
  236.         Keyboard
  237.             bindValue: #encloseKey:
  238.             to: ESC
  239.             followedBy: char].
  240.     'sSuUbBiIx+-' do:
  241.         [:char |
  242.         Keyboard
  243.             bindValue: #changeEmphasisKey:
  244.             to: ESC
  245.             followedBy: char].
  246.     Keyboard
  247.         bindValue: #miniFormatKey:
  248.         to: ESC
  249.         followedBy: $f.
  250.     Keyboard
  251.         bindValue: #selectCurrentTypeInKey:
  252.         to: ESC
  253.         followedBy: Tab.
  254.     Keyboard
  255.         bindValue: #selectCurrentTypeInKey:
  256.         to: #F1!
  257.  
  258. initializeSUNKeys
  259.     "Initialize the mapping for function keys on the SUN type-4 keyboard."
  260.     "ParagraphEditor initializeSUNKeys"
  261.     Keyboard bindValue: #indentedCRKey: to: LF.
  262.     Keyboard bindValue: #againKey: to: #L2.
  263.     Keyboard bindValue: #undoKey: to: #L4.
  264.     Keyboard bindValue: #copySelectionKey: to: #L6.
  265.     Keyboard bindValue: #pasteKey: to: #L8.
  266.     Keyboard bindValue: #cutKey: to: #L10.
  267.     Keyboard bindValue: #doItKey: to: #R1.
  268.     Keyboard bindValue: #printItKey: to: #R2.
  269.     Keyboard bindValue: #inspectItKey: to: #R3.
  270.     Keyboard bindValue: #acceptKey: to: #Enter.
  271.     Keyboard bindValue: #pageUpKey: to: #R9.
  272.     Keyboard bindValue: #pageDownKey: to: #R15! !
  273.  
  274. ParagraphEditor initialize!
  275.  
  276. TextItemEditor initialize!